
import {HttpCode, loginErrorCode, badRequestCode, errorCode, notFoundCode, notLoginCode, successCode, badRequestParamsCode} from "./code"
import { HttpMsg, badRequestMsg, badRequestParamsMsg, errorMsg, loginErrorMsg, noPermissionMsg, notFoundMsg, notLoginMsg, successMsg } from "./msg"

type Response = {
	Code:HttpCode   
	Msg:HttpMsg     
	Data:any
}
export const Success = (ctx, data:any) => {
	ctx.body = {
		Code: successCode,
		Msg:  successMsg,
		Data: data,
	}
}

export const Fail = (ctx , code:HttpCode) => {
	let failMsg:HttpMsg
	switch (code) {
	case notFoundCode:
		failMsg = notFoundMsg
	case errorCode:
		failMsg = errorMsg
	case notLoginCode:
		failMsg = notLoginMsg
	case notFoundCode:
		failMsg = noPermissionMsg
	case badRequestCode:
		failMsg = badRequestMsg
	case loginErrorCode:
		failMsg = loginErrorMsg
	case badRequestParamsCode:
		failMsg = badRequestParamsMsg
	default:
		failMsg = "非法状态"
		code = 0
	}
	ctx.body = {
		Code: code,
		Msg:  failMsg,
		Data: null
	}
}
